var express = require('express');
var request = require('request');

var url = require('url');
var qstr = require("querystring");
var fs = require("fs");
var pro = require('../../property/cuspro');
var auth = require('../../auth/auth');
var util = require('../../util/commonutil');
var router = express.Router();
/* GET home page. */
// router.get('/', function(req, res, next) {
//   res.render('index', { title: 'Expr问问ess22-444' });
// });

// var items=[{title:'文章管理'},{title:'人员管理'}];
router.get('/', function(req, res, next) {
    var items=[{carNo:"车辆",num:0}]
    var itemsF=[{carNo:"车辆",num:0}]
    var pathname = url.parse(req.url).pathname;  //pathname => list

    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}
    var query=req.query;//参数
    var sid = auth.getSessionID(req, res, next);
    arg.sid=sid;
    request({
        url: pro.serveraddr+'/report/queryWarningNum',
        method: "POST",
        qs: arg
    }, function(error, response, body) {
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            if(data ){
                res.render('home/index',{serverurl:pro.serveraddr,warningYear:"",carNo:"车辆",
                    warningNum:"0",warningTitle:"最近七天车辆报警数据分析",ffxsTitle:"最近七天车辆非法行驶数据分析",
                    onlineNum:"0%",onlineTitle:"最近七天车辆在线率数据分析",deptName:"客户",
                    items:data.carNosW,itemsF:data.carNosF
                });
            }else {
                res.render('home/index',{serverurl:pro.serveraddr,warningYear:"",carNo:"车辆",
                    warningNum:"0",warningTitle:"最近七天车辆报警数据分析",ffxsTitle:"最近七天车辆非法行驶数据分析",
                    onlineNum:"0%",onlineTitle:"最近七天车辆在线率数据分析",deptName:"客户",
                    items:items,itemsF:itemsF
                });
            }



        }
    });

});
router.get('/userinfo', function(req, res, next) {
    res.render('home/userinfo');
});
router.get('/changepass', function(req, res, next) {
    //登录
    var sid=auth.getSessionID(req, res, next);
    var arg = url.parse(req.url, true).query;   //arg1 => {name:'a',id:'5'}

    arg.sid=sid;
    request({
        url: pro.serveraddr+'/login/doChangePwd',
        method: "POST",
        qs: arg
    }, function(error, response, body){
        if (!error && response.statusCode == 200) {
            var data=JSON.parse(body);
            res.json(data);
        }
    });
});



module.exports = router;
